<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 86185
  Date: 2021/5/6
  Time: 17:17
  药单的查询
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    //获取项目的根路径
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>


    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="<%=basePath%>layui-v2.6.5/layui/css/layui.css" media="all">
    <script src="<%=basePath%>layui-v2.6.5/layui/layui.js"></script>
    <script src="<%=basePath%>doctor/js/jquery-1.12.4.js"></script>
    <link rel="stylesheet" href="<%=basePath%>swee/sweetalert.css">
    <script src="<%=basePath%>swee/sweetalert-dev.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

    <style type="text/css">

        #demo1 {
            position: absolute;
            left: 600px;
        }

        #head {
            margin-left: 500px;
        }

        .bj {
            width: 100%;
            height: 600px;
            position: absolute;
            top: 0;
            left: 0;
            background-color: #a9a9a9;
            opacity: 0.5;
            display: none;
        }

        .recipe {

            color: #009f95;
            background-color: white;
            width: 800px;
            height: 460px;
            border: 0 solid red;
            /*opacity:0;*/
            position: absolute;
            left: 20%;
            top: 40px;
            display: none;
        }

        .recipe input, textarea {
            color: #009f95;
        }

        .drug {

            position: relative;
            top: -280px;
            left: 0;

        }

        #back {
            position: relative;
            right: -400px;
            width: 100px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            border: 1px solid #0bc9be;
            color: #0bc9be;
            display: inline-block;

        }

    </style>
</head>
<body>


<div class="layui-form-item">
    <div class="layui-input-inline"></div>
</div>
<div id="head">


    <form action="<%=basePath%>MedicineServlet" method="post">
        <div class="layui-input-inline">
            <input type="text" name="userName" lay-verify="required" placeholder="请输入" autocomplete="off"
                   class="layui-input">
        </div>

        <button type="submit" class="layui-btn layui-btn-radius" style="width: 100px">查询</button>
        <%--        <a href="<%=basePath%>queue?doctorId=<%=request.getAttribute("docid")%>&doctorname=<%=request.getAttribute("doctorname")%>"></a><button type="submit"  class="layui-btn layui-btn-radius"   style="width: 100px">返回</button>--%>
        <a href="<%=basePath%>queue?doctorId=<%=request.getAttribute("docid")%>&doctorname=<%=request.getAttribute("doctorname")%>"
           id="back">返回</a>
    </form>
</div>
<table class="layui-table" lay-even="" lay-skin="nob">
    <colgroup>
        <col width="150">
        <col width="150">
        <col width="200">
        <col>
    </colgroup>
    <thead>
    <tr>
        <th>开药记录编号</th>
        <th>诊断号</th>
        <th>用户姓名</th>
        <th>药名</th>
        <th>药品数量</th>
        <th>开药时间</th>
        <th>医生姓名</th>
        <th>用药方法</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody class="bangding">
    <c:forEach items="${requestScope.MedicinePage.list}" var="list">
        <tr>
            <td>${list.id}</td>
            <td>${list.userid}</td>
            <td>${list.username}</td>
            <td>${list.medicine}</td>
            <td>${list.sum}</td>
            <td>${list.time}</td>
            <td>${list.doctorId}</td>
            <td>${list.type}</td>
            <td>
                <button type="submit" class="layui-btn layui-btn-radius" id="upd" style="width: 100px">修改药单</button>
                <button type="submit" class="layui-btn layui-btn-danger layui-btn-radius" id="del" style="width: 100px">
                    删除
                </button>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
</fieldset>

<div id="demo1">
    <c:if test="${requestScope.MedicinePage.currPageNo>1}">
        <a href="<%=basePath%>MedicineServlet?currPageNo=${requestScope.MedicinePage.currPageNo-1}&userName=${userName}&docid=${requestScope.docid}">
            <button class="layui-btn layui-btn-primary layui-border-green">上一页</button>
        </a>
    </c:if>
    ${requestScope.MedicinePage.currPageNo}/${requestScope.MedicinePage.totalCount}
    <c:if test="${requestScope.MedicinePage.currPageNo<requestScope.MedicinePage.totalCount}">
        <a href="<%=basePath%>MedicineServlet?currPageNo=${requestScope.MedicinePage.currPageNo+1}&userName=${userName}&docid=${requestScope.docid}">
            <button class="layui-btn layui-btn-primary layui-border-green">下一页</button>
        </a>
    </c:if>
</div>


<div class="bj"></div>
<div class="recipe">
    <p class="no" style="float: right; width: 30px; font-size:30px">×&nbsp;</p>
    <h1 style="margin: 16px auto; width: 400px;text-align: center">湖南省长沙市华子医院处方笺</h1>

    <form class="layui-form" action="" id="updatetye">
        <div class="layui-form-item">
            <label class="layui-form-label">诊断号：</label>
            <div class="layui-input-block">
                <input type="text" name="id" readonly lay-verify="title" autocomplete="off" placeholder="请输入标题"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">姓名：</label>
            <div class="layui-input-block">
                <input type="text" name="username" readonly lay-verify="required" lay-reqtext="用户名是必填项，岂能为空？"
                       placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label"></label>

                <div class="layui-input-inline">

                    <input type="tel" name="drug" lay-verify="" readonly autocomplete="off" class="layui-input"
                           style="display: none" value="13974050958">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">验证日期：</label>
                <div class="layui-input-inline">
                    <input type="text" name="date" id="date" lay-verify="" placeholder="yyyy-MM-dd" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">


            <div class="layui-inline">
                <label class="layui-form-label">数量：</label>
                <div class="layui-input-inline">
                    <input type="text" name="data" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">医生：</label>
                <div class="layui-input-inline">
                    <input type="tel" name="doctorname" readonly lay-verify="" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>


        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">医嘱：</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <!--<div class="layui-form-item layui-form-text">
          <label class="layui-form-label">编辑器</label>
          <div class="layui-input-block">
            <textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="LAY_demo_editor"></textarea>
          </div>
        </div>-->
        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left:400px;">
                <button type="button" id="update" class="layui-btn" lay-submit="" lay-filter="demo1">确定</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                <button type="no" class="layui-btn layui-btn-primary" class="no">取消</button>
            </div>
        </div>

        <div class="drug">
            <label class="layui-form-label">搜索选择框</label>
            <div class="layui-input-inline">
                <select name="modules" lay-verify="required" lay-search="" id="xiala">
                    <c:forEach items="${requestScope.list}" var="list">
                        <option value="${list.id}">${list.drugname}</option>
                    </c:forEach>
                </select>
            </div>
        </div>


    </form>


</div>
<div>
    <input type="text" style="display: none" id="qwer">
</div>


<script type="text/javascript">
    $(function () {

        //关闭修改
        $(".no").click(function () {
            $(".bj").hide();
            $(".recipe").hide();
        })
        //修改处方
        $(".bangding").on("click", "#upd", function () {
            $(".bj").show();
            $(".recipe").show();

            //取得当前行数所有的td
            var arr = $(this).parent().parent().children().length;

            //给隐藏的编号录值
            $("#qwer").val($(this).parent().parent().children("td:eq(0)").text());


            //给搜索下拉框赋值
            var xl = $(this).parent().parent().children("td:eq(3)").text()


            //循环给文本框录值
            for (var i = 0, j = 1; i < 6; i++, j++) {

                $("#updatetye input:eq(" + i + ")").val($(this).parent().parent().children("td:eq(" + j + ")").text())
            }
            //医嘱文本域的赋值
            $(".layui-textarea").text($(this).parent().parent().children("td:eq(7)").text())

            //文本框互换
            var datetimee = $("#updatetye input:eq(4)").val()
            $("#updatetye input:eq(4)").val($("#updatetye input:eq(3)").val())
            $("#updatetye input:eq(3)").val(datetimee)


        })

        $("#update").click(function () {

            swal({
                    title: "确定修改吗？",
                    text: "",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#68c1f8",
                    confirmButtonText: "确定修改！",
                    cancelButtonText: "取消修改！",
                    closeOnConfirm: false,
                    closeOnCancel: false
                },
                function (isConfirm) {

                    if (isConfirm) {
                        $.ajax({
                            url: "http://localhost:8080/com/MedicineServlet",
                            type: "post",
                            data: {
                                czf: "update",
                                id: $("#qwer").val(),
                                userid: $("#updatetye input:eq(0)").val(),
                                name: $("#updatetye input:eq(1)").val(),
                                drugname: $("#xiala").val(),
                                drugsum: $("#updatetye input:eq(4)").val(),
                                time: $("#updatetye input:eq(3)").val(),
                                doctorname:<%=request.getAttribute("docid")%>,
                                type: $(".layui-textarea").val()
                            },
                            dateType: "json",
                            success: function (data) {
                                swal("修改成功")
                                window.location.replace("http://localhost:8080/com/MedicineServlet?docid=${requestScope.docid}");
                            }
                        })
                    } else {
                        swal("取消！", "操作取消:)",
                            "error");
                    }
                });


        })


        //删除处方
        $(".bangding").on("click", "#del", function () {

            var id = $(this).parent().parent().children("td:eq(0)").text();

            swal({
                    title: "确定删除这条记录吗？",
                    text: "你将无法恢复该虚拟文件！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确定删除！",
                    cancelButtonText: "取消删除！",
                    closeOnConfirm: false,
                    closeOnCancel: false
                },
                function (isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            url: "http://localhost:8080/com/MedicineServlet",
                            type: "post",
                            data: {
                                czf: "delete",
                                id: id
                            },
                            dateType: "json",
                            success: function (data) {
                                swal("删除成功")
                                window.location.replace("http://localhost:8080/com/MedicineServlet?docid=${requestScope.docid}");
                            }

                        })
                    } else {
                        swal("取消！",
                        );
                    }
                });


            // var del=confirm("确定要删除该记录吗？")
            // if(del) {
            //     $.ajax({
            //         url: "http://localhost:8080/com/MedicineServlet",
            //         type: "post",
            //         data: {
            //             czf: "delete",
            //             id: $(this).parent().parent().children("td:eq(0)").text()
            //         },
            //         dateType: "json",
            //         success: function (data) {
            //             alert("删除成功")
            //             window.location.replace("http://localhost:8080/com/MedicineServlet");
            //         }
            //
            //     })
            // }


        })
    })


</script>

</body>
</html>
